//
// File:	BaseRenderable.cpp
// Author:	Thomas TISSOT-DUPONT
// E-mail:	<thomas.tissotdupont@free.fr>
// Create:	26/04/2010 21:27:21
// Purpose:	
//

#include "Base.hpp"
#include "BaseRenderable.hpp"
#include "Trace.hpp"

//------------------------------------------------------------------
// Constructor / Destructor
//------------------------------------------------------------------
BaseRenderable::BaseRenderable()
{
}

BaseRenderable::~BaseRenderable()
{
}

//------------------------------------------------------------------
// Render
//------------------------------------------------------------------
void BaseRenderable::Render(float flX, float flY)
{
	//Compute the screen W/H ratio
	int iWinWidth = GlobalVariables::DisplayManager::Get().GetWindow()->GetWidth();
	int iWinHeight = GlobalVariables::DisplayManager::Get().GetWindow()->GetHeight();
	float flScaleX = static_cast<float>(iWinHeight) / static_cast<float>(iWinWidth);
	float flScaleY = static_cast<float>(iWinWidth) / static_cast<float>(iWinHeight);

	//Compute the screen reference W/H ratio
	int iWinRefWidth = GlobalVariables::DisplayManager::Get().GetWindow()->GetReferenceWidth();
	int iWinRefHeight = GlobalVariables::DisplayManager::Get().GetWindow()->GetReferenceHeight();
	float flRefScaleX = static_cast<float>(iWinWidth) / static_cast<float>(iWinRefWidth);
	float flRefScaleY = static_cast<float>(iWinHeight) / static_cast<float>(iWinRefHeight);

	//Render myself
	sf::Sprite::SetScale(flScaleX * flRefScaleX, flScaleY * flRefScaleY);
	sf::Sprite::SetPosition(flX * flRefScaleX, flY * flRefScaleY);
	GlobalVariables::DisplayManager::Get().Draw(*this);
}

//------------------------------------------------------------------
// Render Color
//------------------------------------------------------------------
void BaseRenderable::SetRenderColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a /* = 255 */)
{
	sf::Sprite::SetColor(sf::Color(r, g, b, a));
}
